//
//  SiterDeviceNetManager.m
//  sHome
//
//  Created by tracyhenry on 2022/8/15.
//  Copyright © 2022年 SiterWell. All rights reserved.
//

#import "SiterDeviceNetManager.h"
#import "SiterAPI.h"
#import "NVLogManager.h"

@implementation SiterDeviceNetManager

//获取设备列表
+ (void) getSingleDeviceInfo:(NSString *)thingName handle:(void(^)(id,NSError *,NSError *)) handler{
    NSDictionary *params = @{
        @"thingName":thingName
    };
    
    [self HttpPOSTBYJSON:[NSString stringWithFormat:@"%@/bind/getInfor",[[Siter sharedInstance] getDomain]] parameters:params completionHandler:^(id responseObj, NSError *error1, NSError *error2) {
        !handler ?: handler(responseObj, error1,error2);
    }];
}

//根据房间获取设备列表
+ (void) getDeviceList:(NSNumber *)roomId handle:(void(^)(id,NSError *,NSError *)) handler{
    NSDictionary *params =nil;
    if(roomId!=nil){
        params = @{@"roomId":roomId};
    }

    
    [self HttpPOSTBYJSON:[NSString stringWithFormat:@"%@/bind/getRoomDeviceList",[[Siter sharedInstance] getDomain]] parameters:roomId==nil?@{}:params completionHandler:^(id responseObj, NSError *error1, NSError *error2) {
        !handler ?: handler(responseObj, error1,error2);
    }];
}


//获取所有设备列表
+ (void) getDeviceList:(void(^)(id,NSError *,NSError *)) handler{
    [self HttpPOSTBYJSON:[NSString stringWithFormat:@"%@/bind/getDeviceList",[[Siter sharedInstance] getDomain]] parameters:@{} completionHandler:^(id responseObj, NSError *error1, NSError *error2) {
        !handler ?: handler(responseObj, error1,error2);
    }];
}

//获取共享设备列表
+ (void) getSharePageList:(void(^)(id,NSError *,NSError *)) handler{
    [self HttpPOSTBYJSON:[NSString stringWithFormat:@"%@/bind/getSharePageList",[[Siter sharedInstance] getDomain]] parameters:@{} completionHandler:^(id responseObj, NSError *error1, NSError *error2) {
        !handler ?: handler(responseObj, error1,error2);
    }];
}




//绑定设备
+ (void) bindDevice:(nonnull NSString *)thingName withRoomId:(NSNumber *)roomId handle:(void(^)(id,NSError *,NSError *)) handler{
    NSDictionary *params;
    if(roomId==nil){
        params = @{
            @"thingName":thingName,
        };
    }else{
        params = @{
            @"thingName":thingName,
            @"roomId":roomId
        };
    }
    

    [self HttpPOSTBYJSON:[NSString stringWithFormat:@"%@/bind/bindUser/v2",[[Siter sharedInstance] getDomain]] parameters:params completionHandler:^(id responseObj, NSError *error1, NSError *error2) {
        !handler ?: handler(responseObj, error1,error2);
    }];
}

//绑定设备(网关接口)
+ (void) bindDeviceByGateway:(nonnull NSString *)thingName withRoomId:(NSNumber *)roomId handle:(void(^)(id,NSError *,NSError *)) handler{
    NSDictionary *params;
    if(roomId==nil){
        params = @{
            @"thingName":thingName,
        };
    }else{
        params = @{
            @"thingName":thingName,
            @"roomId":roomId
        };
    }
    

    [self HttpPOSTBYJSON:[NSString stringWithFormat:@"%@/bind/bindUser",[[Siter sharedInstance] getDomain]] parameters:params completionHandler:^(id responseObj, NSError *error1, NSError *error2) {
        !handler ?: handler(responseObj, error1,error2);
    }];
}


//绑定设备
+ (void) unbindDevice:(nonnull NSString *)thingName handle:(void(^)(id,NSError *,NSError *)) handler{
    NSDictionary *params = @{
        @"thingName":thingName
    };
    
    [self HttpPOSTBYJSON:[NSString stringWithFormat:@"%@/bind/unBind/v2",[[Siter sharedInstance] getDomain]] parameters:params completionHandler:^(id responseObj, NSError *error1, NSError *error2) {
        !handler ?: handler(responseObj, error1,error2);
    }];
}



//修改设备名称
+ (void) modifyDeviceName:(NSString *)deviceName withThingName:(NSString *)thingName handle:(void(^)(id,NSError *,NSError *)) handler{
    NSDictionary *dic = @{
                          @"deviceName" : deviceName,
                          @"thingName" : thingName
                          };
    [self HttpPOSTBYJSON:[NSString stringWithFormat:@"%@/bind/updateDeviceName",[[Siter sharedInstance] getDomain]] parameters:dic completionHandler:^(id responseObj, NSError *error1, NSError *error2) {
        !handler ?: handler(responseObj, error1,error2);
    }];
}

//修改子设备名称
+ (void) modifySubDeviceName:(NSString *)deviceName withThingName:(NSString *)thingName withDeviceCode:(NSString *)deviceCode handle:(void(^)(id,NSError *,NSError *)) handler{
    NSDictionary *dic = @{
                          @"deviceName" : deviceName,
                          @"deviceCode" : deviceCode,
                          @"gateway" : thingName
                          };
    [self HttpPOSTBYJSON:[NSString stringWithFormat:@"%@/sub/modifyBySnAndGatething",[[Siter sharedInstance] getDomain]] parameters:dic completionHandler:^(id responseObj, NSError *error1, NSError *error2) {
        !handler ?: handler(responseObj, error1,error2);
    }];
}




//获取设备OTA信息
+ (void) getOTA:(NSArray *)params handle:(void(^)(id,NSError *,NSError *)) handler{

    [self HttpPOST:[NSString stringWithFormat:@"%@/external/device/fw/ota/check",[[Siter sharedInstance] getDomain]] parameters:params completionHandler:^(id responseObj, NSError *error1, NSError *error2) {
        !handler ?: handler(responseObj, error1,error2);
    }];
}


//获取新的网关设备
+ (void) getNewDeviceList:(NSString *)pinCode handle:(void(^)(id,NSError *,NSError *)) handler{

    NSDictionary *params = @{@"pinCode":pinCode};
    
    [self HttpPOST:[NSString stringWithFormat:@"%@/user/getNewDeviceList",[[Siter sharedInstance] getDomain]] parameters:params completionHandler:^(id responseObj, NSError *error1, NSError *error2) {
        !handler ?: handler(responseObj, error1,error2);
    }];
}



//获取某个设备的经典影子
+ (void) getDeviceShadow:(NSString *)thingName handle:(void(^)(id,NSError *,NSError *)) handler{
    NSDictionary *params = @{
        @"thingName":thingName
    };
    
    [self HttpPOSTBYJSON:[NSString stringWithFormat:@"%@/deviceShadow/getThingShadow",[[Siter sharedInstance] getDomain]] parameters:params completionHandler:^(id responseObj, NSError *error1, NSError *error2) {
        !handler ?: handler(responseObj, error1,error2);
    }];
}


//获取某个设备ShadowName的影子状态
+ (void) getDeviceShadowWithShadowName:(NSString *)thingName withShadowName:(NSString *)shadowName handle:(void(^)(id,NSError *,NSError *)) handler{
    NSDictionary *params = @{
        @"thingName":thingName,
        @"shadowName":shadowName
    };
    
    [self HttpPOSTBYJSON:[NSString stringWithFormat:@"%@/deviceShadow/getThingShadowWithShadowName",[[Siter sharedInstance] getDomain]] parameters:params completionHandler:^(id responseObj, NSError *error1, NSError *error2) {
        !handler ?: handler(responseObj, error1,error2);
    }];
}


//添加温控器定时模式
+(void) addTimerMode:(NSString *)thingName withMode:(NSNumber *)mode withModeName:(NSString *)modeName withTempCool:(float)temp_cool withTempHot:(float)temp_hot withHandler:(void (^)(id, NSError *, NSError *))handler{
 
    NSDictionary *dic = @{@"thingName":thingName,
                          @"id":mode,
                          @"modeName":modeName,
                          @"heatTemperature":@(temp_hot),
                          @"coolTemperature":@(temp_cool)
    };
    
    [self HttpPOSTBYJSON:[NSString stringWithFormat:@"%@/hvac/addHVACMode",[[Siter sharedInstance] getDomain]] parameters:dic completionHandler:^(id responseObj, NSError *error1, NSError *error2) {
        !handler ?: handler(responseObj, error1,error2);
    }];
}

//编辑温控器定时模式
+(void) editTimerMode:(NSString *)thingName withMode:(NSNumber *)mode withModeName:(NSString *)modeName withTempCool:(float)temp_cool withTempHot:(float)temp_hot withHandler:(void (^)(id, NSError *, NSError *))handler{
 
    NSDictionary *dic = @{@"thingName":thingName,
                          @"id":mode,
                          @"modeName":modeName,
                          @"heatTemperature":@(temp_hot),
                          @"coolTemperature":@(temp_cool)
    };
    
    [self HttpPOSTBYJSON:[NSString stringWithFormat:@"%@/hvac/addHVACMode",[[Siter sharedInstance] getDomain]] parameters:dic completionHandler:^(id responseObj, NSError *error1, NSError *error2) {
        !handler ?: handler(responseObj, error1,error2);
    }];
}

//下发控制设备通过设备影子
+(void) commandToShadow:(NSString *)thingName withShadowName:(NSString *)shadowName withShadow:(NSString *)shadow withHandler:(void (^)(id, NSError *, NSError *))handler{
 
    NSDictionary *dic = @{@"thingName":thingName,
                          @"shadowName":shadowName,
                          @"payload":shadow
    };
    
    [self HttpPOSTBYJSON:[NSString stringWithFormat:@"%@/deviceShadow/updateThingShadowWithName",[[Siter sharedInstance] getDomain]] parameters:dic completionHandler:^(id responseObj, NSError *error1, NSError *error2) {
        !handler ?: handler(responseObj, error1,error2);
    }];
}


//下发控制HVAC设备模式
+(void) commandHvacMode:(NSString *)thingName withHotMode:(BOOL)isHot withCoolMode:(BOOL)isCool withFanMode:(BOOL)isFan withECO:(BOOL)isECO withHandler:(void (^)(id, NSError *, NSError *))handler{
 
    int cool = isCool?0x01:0x00;
    int hot = isHot?0x02:0x00;
    int fan = isFan?0x04:0x00;
    int eco = isECO?0x08:0x00;
    int ade = cool|hot|fan|eco;

    
    NSDictionary *dic =@{@"thingName":thingName,@"payload":@{@"command":@"SetThermostatMode",
                                                             @"param":@{@"value":@(ade)}}};
    
    [self HttpPOSTBYJSON:[NSString stringWithFormat:@"%@/deviceCommand/issueCommand",[[Siter sharedInstance] getDomain]] parameters:dic completionHandler:^(id responseObj, NSError *error1, NSError *error2) {
        !handler ?: handler(responseObj, error1,error2);
    }];
}

//下发设置HVAC设置温度
+(void) commandHvacTemp:(NSString *)thingName withTemp:(float)temp withUnit:(NSString *)devunit withHandler:(void (^)(id, NSError *, NSError *))handler{
 
    
    NSString *unit = @"";
    if([devunit isEqualToString:@"1"]){
        unit = @"C";
    }else{
        unit = @"F";
    }
    
    NSDictionary *dic =@{@"thingName":thingName,@"payload":@{@"command":@"SetTargetTemperature",
                                                                 @"param":@{@"value":@(temp),@"scale":unit}}};
    
    [self HttpPOSTBYJSON:[NSString stringWithFormat:@"%@/deviceCommand/issueCommand",[[Siter sharedInstance] getDomain]] parameters:dic completionHandler:^(id responseObj, NSError *error1, NSError *error2) {
        !handler ?: handler(responseObj, error1,error2);
    }];
}

//下发设置HVAC温度单位
+(void) commandHvacDevUnit:(NSString *)thingName withThingTypeName:(NSString *)thingTypeName withUnit:(NSString *)devUnit withHandler:(void (^)(id, NSError *, NSError *))handler{
    
    NSNumber *unit = @0;
    if([devUnit isEqualToString:@"1"]){
        unit = @1;
    }
    
    NSDictionary *dic =@{@"thingName":thingName,@"shadowName":thingTypeName,@"command":@{@"param":unit}};
    
    [self HttpPOSTBYJSON:[NSString stringWithFormat:@"%@/hvac/setTempUnit",[[Siter sharedInstance] getDomain]] parameters:dic completionHandler:^(id responseObj, NSError *error1, NSError *error2) {
        !handler ?: handler(responseObj, error1,error2);
    }];
}

//检测OTA可更新状态
+(void) checkOTAversion:(NSString *)thingName withHandler:(void (^)(id, NSError *, NSError *))handler{
 
    NSDictionary *de = @{@"thingName":thingName};
    
    [self HttpPOSTBYJSON:[NSString stringWithFormat:@"%@/firmware/version/check",[[Siter sharedInstance] getDomain]] parameters:de completionHandler:^(id responseObj, NSError *error1, NSError *error2) {
        !handler ?: handler(responseObj, error1,error2);
    }];
}

//查询设备升级进度
+(void) getOTAProgress:(NSString *)thingName withJobId:(NSString *)jobid withHandler:(void (^)(id, NSError *, NSError *))handler{
 
    NSDictionary *de = @{@"thingName":thingName,@"jobId":jobid};
    [self HttpPOSTBYJSON:[NSString stringWithFormat:@"%@/firmware/version/getDeviceOTAState",[[Siter sharedInstance] getDomain]] parameters:de completionHandler:^(id responseObj, NSError *error1, NSError *error2) {
        !handler ?: handler(responseObj, error1,error2);
    }];
}

//下发升级命令
+(void) otaCommandToDevice:(NSString *)thingName withHandler:(void (^)(id, NSError *, NSError *))handler{
 
    NSDictionary *de = @{@"thingName":thingName};
    [self HttpPOSTBYJSON:[NSString stringWithFormat:@"%@/firmware/version/update",[[Siter sharedInstance] getDomain]] parameters:de completionHandler:^(id responseObj, NSError *error1, NSError *error2) {
        !handler ?: handler(responseObj, error1,error2);
    }];
}


//获取hvac预设置模式
+(void) getHvacModeList:(NSString *)thingName withHandler:(void (^)(id, NSError *, NSError *))handler{

    NSDictionary *de = @{@"thingName":thingName};
    [self HttpPOSTBYJSON:[NSString stringWithFormat:@"%@/hvac/getModeList",[[Siter sharedInstance] getDomain]] parameters:de completionHandler:^(id responseObj, NSError *error1, NSError *error2) {
        !handler ?: handler(responseObj, error1,error2);
    }];
}

//新增hvac预设置模式
+(void) addHvacMode:(TimerPresetMode *)preMode withHandler:(void (^)(id, NSError *, NSError *))handler{

    NSDictionary *dic = @{@"thingName":preMode.thingName,
                         @"iconValue":preMode.iconValue,
                         @"modeName":preMode.modeName,
                         @"coolTemperature":@([preMode.coolTemperature floatValue]),
                         @"heatTemperature":@([preMode.heatTemperature floatValue]),
                        @"unitValue":preMode.unitValue
    };
    [self HttpPOSTBYJSON:[NSString stringWithFormat:@"%@/hvac/addMode",[[Siter sharedInstance] getDomain]] parameters:dic completionHandler:^(id responseObj, NSError *error1, NSError *error2) {
        !handler ?: handler(responseObj, error1,error2);
    }];
}

//删除hvac预设置模式
+(void) deleteHvacMode:(NSNumber *)modeId withHandler:(void (^)(id, NSError *, NSError *))handler{

    NSDictionary *dic = @{@"id":modeId};
    [self HttpPOSTBYJSON:[NSString stringWithFormat:@"%@/hvac/deleteMode",[[Siter sharedInstance] getDomain]] parameters:dic completionHandler:^(id responseObj, NSError *error1, NSError *error2) {
        !handler ?: handler(responseObj, error1,error2);
    }];
}


//编辑hvac预设置模式
+(void) editHvacMode:(TimerPresetMode *)preMode withHandler:(void (^)(id, NSError *, NSError *))handler{

    NSDictionary *dic = @{@"id":preMode.modeId,@"coolTemperature":@([preMode.coolTemperature floatValue]),@"heatTemperature":@([preMode.heatTemperature floatValue])};
    [self HttpPOSTBYJSON:[NSString stringWithFormat:@"%@/hvac/editMode",[[Siter sharedInstance] getDomain]] parameters:dic completionHandler:^(id responseObj, NSError *error1, NSError *error2) {
        !handler ?: handler(responseObj, error1,error2);
    }];
}


//获取告警中心列表
+ (void) getMessageRecordList:(NSString *)thingName withDeviceCode:(NSString *)deviceCode  withPageNum:(NSNumber *)pageNum withPageSize:(NSNumber *)pageSize withHandler:(void(^)(id,NSError *,NSError *)) handler{
    
    NSDictionary *dic = (deviceCode==nil||[@"" isEqualToString:deviceCode])? @{
      @"thingName":thingName,
      @"pageNum": pageNum,
      @"pageSize": pageSize
    }:@{
        @"thingName":thingName,
        @"deviceCode":deviceCode,
        @"pageNum": pageNum,
        @"pageSize": pageSize
      };
    
    return [self HttpPOSTBYJSON:[NSString stringWithFormat:@"%@/messageRecord/list",[[Siter sharedInstance] getDomain]] parameters:dic completionHandler:^(id responseObj, NSError *error1, NSError *error2) {
        !handler ?: handler(responseObj, error1,error2);
    }];
}

//设置某条报警已读
+ (void) setAlarmRead:(NSString *)messageId  handle:(void(^)(id,NSError *,NSError *))handler{
    NSArray *param = @[messageId];
    
    
    return [self HttpPOSTBYJSON:[NSString stringWithFormat:@"%@/messageRecord/idRead",[[Siter sharedInstance] getDomain]] parameters:param completionHandler:^(id responseObj, NSError *error1, NSError *error2) {
        !handler ?: handler(responseObj, error1,error2);
    }];
}


//设置某个设备设置成所有已读
+ (void) setAlarmAllRead:(NSString *)thingName withDeviceCode:(NSString *)deviceCode  handle:(void(^)(id,NSError *,NSError *))handler{
    NSDictionary *param = @{@"thingName":thingName,@"deviceCode":deviceCode};
    
    
    return [self HttpPOSTBYJSON:[NSString stringWithFormat:@"%@/messageRecord/allRead",[[Siter sharedInstance] getDomain]] parameters:param completionHandler:^(id responseObj, NSError *error1, NSError *error2) {
        !handler ?: handler(responseObj, error1,error2);
    }];
}


//获取设备告警推送设置(GS888/GS886)
+ (void) getDevicePushConfig:(NSString *)thingName handle:(void(^)(id,NSError *,NSError *)) handler{
    NSDictionary *params = @{
        @"thingName":thingName
    };
    
    [self HttpPOSTBYJSON:[NSString stringWithFormat:@"%@/dmsWarnConfig/detail",[[Siter sharedInstance] getDomain]] parameters:params completionHandler:^(id responseObj, NSError *error1, NSError *error2) {
        !handler ?: handler(responseObj, error1,error2);
    }];
}

//更新设备告警推送设置(GS888/GS886)
+ (void) updateDevicePushConfig:(NSNumber *)configId withCode:(NSString *)code withOpen:(NSNumber *)isOpen handle:(void(^)(id,NSError *,NSError *)) handler{
    NSDictionary *params = @{
        @"id":configId,
        @"code":code,
        @"isOpen":isOpen
    };
    
    [self HttpPOSTBYJSON:[NSString stringWithFormat:@"%@/dmsWarnConfig/update",[[Siter sharedInstance] getDomain]] parameters:params completionHandler:^(id responseObj, NSError *error1, NSError *error2) {
        !handler ?: handler(responseObj, error1,error2);
    }];
}

//获取自测日志
+ (void) getMessageRecordListBySelfTest:(NSString *)thingName  withPageNum:(NSNumber *)pageNum withPageSize:(NSNumber *)pageSize withHandler:(void(^)(id,NSError *,NSError *)) handler{

    NSDictionary *dic = @{
      @"thingName":thingName,
      @"pageNum": pageNum,
      @"pageSize": pageSize
    };
    
    return [self HttpPOSTBYJSON:[NSString stringWithFormat:@"%@/messageRecord/selfTestList",[[Siter sharedInstance] getDomain]] parameters:dic completionHandler:^(id responseObj, NSError *error1, NSError *error2) {
        !handler ?: handler(responseObj, error1,error2);
    }];
}

//获取Smoke日曲线
+ (void) getCurveSMDay:(NSString *)thingName withStartTime:(NSString *)startTime withTimeZone:(NSString *)timeZone withHandler:(void(^)(id,NSError *,NSError *)) handler{

    NSDictionary *dic = @{
      @"thingName":thingName,
      @"timeBegin":startTime,
      @"timeZone":timeZone
    };
    
    return [self HttpPOSTBYJSON:[NSString stringWithFormat:@"%@/smoke/hourlist",[[Siter sharedInstance] getDomain]] parameters:dic completionHandler:^(id responseObj, NSError *error1, NSError *error2) {
        !handler ?: handler(responseObj, error1,error2);
    }];
}


//获取Smoke年/月曲线
+ (void) getCurveSMYear:(NSString *)thingName withStartTime:(NSString *)startTime  withHandler:(void(^)(id,NSError *,NSError *)) handler{

    NSDictionary *dic = @{
      @"thingName":thingName,
      @"timeBegin":startTime
    };
    
    return [self HttpPOSTBYJSON:[NSString stringWithFormat:@"%@/smoke/monthlist",[[Siter sharedInstance] getDomain]] parameters:dic completionHandler:^(id responseObj, NSError *error1, NSError *error2) {
        !handler ?: handler(responseObj, error1,error2);
    }];
}

//获取CO日曲线
+ (void) getCurveCODay:(NSString *)thingName withStartTime:(NSString *)startTime withTimeZone:(NSString *)timeZone withHandler:(void(^)(id,NSError *,NSError *)) handler{

    NSDictionary *dic = @{
      @"thingName":thingName,
      @"timeBegin":startTime,
      @"timeZone":timeZone
    };
    
    return [self HttpPOSTBYJSON:[NSString stringWithFormat:@"%@/co/hourlist",[[Siter sharedInstance] getDomain]] parameters:dic completionHandler:^(id responseObj, NSError *error1, NSError *error2) {
        !handler ?: handler(responseObj, error1,error2);
    }];
}

//获取CO年/月曲线
+ (void) getCurveCOYear:(NSString *)thingName withStartTime:(NSString *)startTime withHandler:(void(^)(id,NSError *,NSError *)) handler{

    NSDictionary *dic = @{
      @"thingName":thingName,
      @"timeBegin":startTime
    };
    
    return [self HttpPOSTBYJSON:[NSString stringWithFormat:@"%@/co/monthlist",[[Siter sharedInstance] getDomain]] parameters:dic completionHandler:^(id responseObj, NSError *error1, NSError *error2) {
        !handler ?: handler(responseObj, error1,error2);
    }];
}

//解绑分享设备
+ (void) unbindShareDevice:(NSString *)thingName withHandler:(void(^)(id,NSError *,NSError *)) handler{

    NSDictionary *dic = @{
      @"thingName":thingName
    };
    
    return [self HttpPOSTBYJSON:[NSString stringWithFormat:@"%@/deviceShare/selfDelete",[[Siter sharedInstance] getDomain]] parameters:dic completionHandler:^(id responseObj, NSError *error1, NSError *error2) {
        !handler ?: handler(responseObj, error1,error2);
    }];
}

//获取网关下的子设备列表
+ (void) getDeviceListFromGateway:(NSString *)thingName withHandler:(void(^)(id,NSError *,NSError *)) handler{

    NSDictionary *dic = @{
      @"gateway":thingName
    };
    
    return [self HttpPOSTBYJSON:[NSString stringWithFormat:@"%@/sub/subDeviceList",[[Siter sharedInstance] getDomain]] parameters:dic completionHandler:^(id responseObj, NSError *error1, NSError *error2) {
        !handler ?: handler(responseObj, error1,error2);
    }];
}


+(NSString *)convertToJsonData:(NSDictionary *)dict{
    NSError *error;
    NSData *jsonData = [NSJSONSerialization dataWithJSONObject:dict options:NSJSONWritingPrettyPrinted error:&error];
    NSString *jsonString;
    
    if (!jsonData) {
        NVLogInfo(@"%@",error);
    }else{
        jsonString = [[NSString alloc]initWithData:jsonData encoding:NSUTF8StringEncoding];
    }
    NSMutableString *mutStr = [NSMutableString stringWithString:jsonString];
    
    NSRange range = {0,jsonString.length};
    
    [mutStr replaceOccurrencesOfString:@" " withString:@"" options:NSLiteralSearch range:range];
    NSRange range2 = {0,mutStr.length};
    [mutStr replaceOccurrencesOfString:@"\n" withString:@"" options:NSLiteralSearch range:range2];
    return mutStr;
    
}

@end
